home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / iconv8_l.arc / PROGS.ARC / itab.icn < prev    next >
Encoding:
Text File  |  1990-03-08  |  1.6 KB  |  65 lines

  1. ############################################################################
  2. #
  3. #    Name:    itab.icn
  4. #
  5. #    Title:    Entab an Icon program
  6. #
  7. #    Author:    Robert J. Alexander
  8. #
  9. #    Date:    December 5, 1989
  10. #
  11. ############################################################################
  12. #
  13. #  itab -- Entab an Icon program, leaving quoted strings alone.
  14. #
  15. #       itab [input-tab-spacing] [output-tab-spacing] 
  16. #                       < source-program > entabbed-program
  17. #
  18. #  Observes Icon Programming Language conventions for escapes and
  19. #  continuations in string constants.  Input and output tab spacing
  20. #  defaults to 8.
  21. #
  22. ############################################################################
  23.  
  24. global mapchars,intabs
  25.  
  26. procedure main(arg)
  27.    local outtabs, line, c, nonwhite, delim
  28.  
  29.    intabs := (arg[1] | 8) + 1
  30.    outtabs := (arg[2] | 8) + 1
  31.    line := ""
  32.    while c := readx() do {
  33.       if not any(' \t',c) then nonwhite := 1
  34.       case c of {
  35.      "\n": {
  36.         write(map(entab(line,outtabs),\mapchars," \t") | line)
  37.         line := ""
  38.         nonwhite := &null
  39.         }
  40.      "'" | "\"": {
  41.         (/delim := c) | (delim := &null)
  42.         line ||:= c
  43.         }
  44.      "\\": line ||:= c || readx()
  45.      default: {
  46.         line ||:= if \delim & \nonwhite & \mapchars then
  47.           map(c," \t",mapchars) else c
  48.         }
  49.      }
  50.       }
  51. end
  52.  
  53. procedure readx()
  54.    static buf,printchars
  55.    initial {
  56.       buf := ""
  57.       printchars := &cset[33:128]
  58.       }
  59.    if *buf = 0 then {
  60.       buf := detab(read(),intabs) || "\n" | fail
  61.       mapchars := (printchars -- buf)[1+:2] | &null
  62.       }
  63.    return 1(.buf[1],buf[1] := "")
  64. end
  65.